/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.shop;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.hk.shop.entity.shop.HkShopAccount;
import com.thinkgem.jeesite.modules.hk.shop.service.shop.HkShopAccountService;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 店铺提现信息Controller
 *
 * @author 李欣荣
 * @version 2018-11-19
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/shop/hkShopAccount")
public class HkShopAccountController extends BaseController {

    @Autowired
    private HkShopAccountService hkShopAccountService;

    @ModelAttribute
    public HkShopAccount get(@RequestParam(required = false) String id) {
        HkShopAccount entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = hkShopAccountService.get(id);
        }
        if (entity == null) {
            entity = new HkShopAccount();
        }
        return entity;
    }

    @RequiresPermissions("shop:shop:hkShopAccount:view")
    @RequestMapping(value = {"list", ""})
    public String list(HkShopAccount hkShopAccount, HttpServletRequest request, HttpServletResponse response, Model model) {
        hkShopAccount.setShopId(UserUtils.getShopId());
        Page<HkShopAccount> page = hkShopAccountService.findPage(new Page<HkShopAccount>(request, response), hkShopAccount);
        model.addAttribute("page", page);
        return "hk/shop/shop/hkShopAccountList";
    }

    @RequiresPermissions("shop:shop:hkShopAccount:view")
    @RequestMapping(value = "form")
    public String form(HkShopAccount hkShopAccount, Model model) {
        model.addAttribute("hkShopAccount", hkShopAccount);
        return "hk/shop/shop/hkShopAccountForm";
    }

    @RequiresPermissions("shop:shop:hkShopAccount:edit")
    @RequestMapping(value = "save")
    public String save(HkShopAccount hkShopAccount, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, hkShopAccount)) {
            return form(hkShopAccount, model);
        }
        if (StringUtils.isBlank(UserUtils.getShopId())) {
            addMessage(redirectAttributes, "登录失效，请退出重新登录");
            return "redirect:" + Global.getAdminPath();
        }
        hkShopAccount.setShopId(UserUtils.getShopId());
        hkShopAccountService.save(hkShopAccount);
        addMessage(redirectAttributes, "保存店铺账户信息成功");
        return "redirect:" + Global.getAdminPath() + "/shop/shop/hkShopAccount/?repage";
    }

    @RequiresPermissions("shop:shop:hkShopAccount:edit")
    @RequestMapping(value = "delete")
    public String delete(HkShopAccount hkShopAccount, RedirectAttributes redirectAttributes) {
        hkShopAccountService.delete(hkShopAccount);
        addMessage(redirectAttributes, "删除店铺账户信息成功");
        return "redirect:" + Global.getAdminPath() + "/shop/shop/hkShopAccount/?repage";
    }

}